import { _decorator, Component, Node, sys } from 'cc';
const { ccclass, property } = _decorator;

export class User {
    private static readonly KEY: string = "USER_DATA";

    private static _inst: User;
    public static get inst(): User {
        if (this._inst == null) {
            this._inst = new User();
        }
        return this._inst;
    }

    public get Data() : UserDta {
        return this._userData;
    }
    private _userData: UserDta = null;

    constructor() {
        this.Load();
    }

    public Save() : void {
        let jsonData = JSON.stringify(this._userData ? this._userData : new UserDta());
        sys.localStorage.setItem(User.KEY,jsonData);
    }

    public Load() : void {
        let jsonData = sys.localStorage.getItem(User.KEY);
        if (jsonData)
            this._userData = JSON.parse(jsonData);
    }
}

export class UserDta {
    public level: number = 0;
    public money: number = 0;
}

export class SettingDta {
    public BGMVolume : number = 0;
    public money: number = 0;
}